1. /* slcomult.cpp by K.Tsuru */
  2. // function ID = 902
  3. /**************************
  4. SLComplex class
  5. multiplication (*this)*z = (a + bi)*(c + di)
  6. **************************/
  7. #ifndef SN_H
  8. #include "sn.h"
  9. #endif
  10. #define UsesSimpleCLCLMult 0
  11. SLComplex& SLComplex::operator*=(const SLComplex& z) {
  12. #if !UsesSimpleCLCLMult // UsesSimpleCLCLMult 0
  13. if ( IsZero(902) ) return *this; // a = b= 0
  14. if ( z.IsZero(902) ) { // c = d = 0
  15. SetZero(); return *this;
  16. }
  17. //cout << "UsesSimpleCLCLMult = " << UsesSimpleCLCLMult << endl;
  18. // d = 0, (a+bi)*c
  19. if (z.im.Sign(903) == SNumber::ZERO) return (*this) *= z.re;
  20. // c = 0, (a+bi)*di = -b*d +(a*d)i
  21. if (z.re.Sign(903) == SNumber::ZERO) {
  22. const SLong r = -im * z.im;
  23. im = re * z.im;
  24. re = r;
  25. return *this;
  26. }
  27. // if(&x == &y) { // z * z can be speed-up by z = a + ib, z^2 = a^2-b^2 + 2iab
  28. if(*this == z) { // Overhead is very small comparing above.
  29. SLong temp(0.0); // (a+ai)^2 = 2a^2i
  30. if (re != im) temp = re * re - im * im;
  31. im = re * im; im *= 2; // = DsMult(im, 2); // change since version 2.192
  32. re = temp;
  33. return *this;
  34. } else {
  35. #define UseCLCLMult3Times 1 // since version 2.3
  36. #if !UseCLCLMult3Times // UseCLCLMult3Times 0
  37. // (a + bi)*(c + di) = a*c - b*d +(a*d + b*c)i
  38. const SLong temp = re * z.re - im * z.im;
  39. im = re * z.im + im * z.re;
  40. re = temp;
  41. #else // UseCLCLMult3Times 1
  42. /*******************************
  43. (a + bi)*(c + di) = a*c - b*d +(a*d + b*c)i
  44. = a*(c -d) + d*(a -b)+{b*(c+d) + d*(a -b)}i
  45. = (re + i*im)*(z.re + i*z.im)
  46. Let re = a, im = b, z.re = c, z.im = d, temp = d*(a -b).
  47. ***********************************/
  48. //cout << "UseCLCLMult3Times = " << UseCLCLMult3Times << endl;
  49. const SDouble temp = z.im * (re - im); // three times *operator()
  50. re = re * (z.re - z.im) + temp; // a*(c-d)+temp
  51. im = im * (z.re + z.im) + temp; // b*(c+d)+temp
  52. #endif // UseCLCLMult3Times end
  53. return *this;
  54. }
  55. #else // UsesSimpleCLCLMult 1
  56. if (z.im.Sign(902) == SNumber::ZERO) return (*this) *= z.re;
  57. const SLong temp = re * z.re - im * z.im;
  58. im = re * z.im + im * z.re;
  59. re = temp;
  60. return *this;
  61. #endif
  62. }

slcomult.cpp : last modifiled at 2016/08/04 15:24:08(2,162 bytes)
created at 2017/10/06 15:21:28
The creation time of this html file is 2017/10/06 15:27:09 (Fri Oct 06 15:27:09 2017).